﻿using System;
using System.Collections.Generic;
using System.Linq;

public class Order
{
    public int OrderId { get; set; }
    public string Customer { get; set; }
    public List<OrderDetail> OrderDetails { get; set; } = new List<OrderDetail>();

    public decimal TotalAmount => OrderDetails.Sum(item => item.UnitPrice * item.Quantity);

    public override bool Equals(object obj)
    {
        if (obj is Order order)
        {
            return OrderId == order.OrderId;
        }
        return false;
    }

    public override int GetHashCode()
    {
        return OrderId;
    }

    public override string ToString()
    {
        string details = string.Join(Environment.NewLine, OrderDetails.Select(d => d.ToString()));
        return $"订单号: {OrderId}, 客户: {Customer}, 总金额: {TotalAmount:C}\n订单明细:\n{details}";
    }
}
